AI Lessons
Lesson 15: Using audio classifier in our project

Purpose: Apply an exported, custom-trained audio classifier model to trigger interactive actions in a web application.

No. of Classes

1 - (Time : 1 hour 30 minutes, Laptops/desktops : 10, Students strength : 15 to 20).

Materials Required

Laptop / Desktop with Internet connection / Wi-Fi.

A working microphone and headphones or speakers.

Visual Studio Code (or code editor) and base starter project files.

Prior knowledge
  • Training custom audio models using Teachable Machine
  • Model labels, background noise, and confidence scores
  • Basic HTML/JavaScript conditional statements
Exercises

Exercise (1)



  • Export your trained audio model from Teachable Machine (or use your downloaded model files from Lesson 14).
  • Download the Base Code and open it in your code editor.
  • Link your audio model URL inside the code to replace the placeholder `model Url`.
  • Map each sound class label to a specific action in the web game.
  • Run the application, trigger sounds using your microphone, and verify that the application responds only when confidence thresholds are met.

Solutions



Teacher's Instruction:
  1. Briefly review Lesson 14, highlighting how classes, audio samples, and model files (`model.json`, `metadata.json`) connect to application code.
  2. Demonstrate the project integration to the student step-by-step
  3. Explain asynchronous loading (`await` / callbacks) so students understand why the web app needs time to load the model before listening.
  4. Demonstrate continuous audio classification (listening loops) versus discrete user interactions.
  5. Show how `if` / `else if` logic checks top prediction labels and triggers specific game movements or state changes.
  6. Emphasize setting a confidence threshold (e.g., `probability > 0.85`) to avoid triggering actions on background noise or partial matches.
  7. Discuss some real world applications for a audio classification system?
  8. Points to Ponder:
    • Smart speakers wait for a "wake word" (like Hey Siri, Alexa or OK Google) before processing commands. How does a device listen for a wake word locally on your hardware without constantly sending all your private home conversations to cloud servers? Where should we draw the line between convenience and privacy?